<template>
  <!-- 班级列表 -->
  <div class="section-content" id="classesList">
    <h2>专业信息</h2>
    <div class="content">
      <div class="content-info">
        <h3>专业数据</h3>
        <div>
          <table border="1">
            <thead>
              <tr>
                <th>专业名称</th>
                <th>授课教师</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody id="classesTb">
              <tr v-for="item in subjectsata" :key="item._id">            
                <td>{{ item.name }}</td>
                <td>授课教师</td>
                <td>
                  <a href="#">修改</a>
                  <a href="#" @click.prevent="deleteSubjects(item._id)">删除</a>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from "../http/api";
export default {
  data() {
    return {
      pages: 0,
      total: 0,
     subjectsata: [],
      currentPage: 1,
      pageSize: 20,
    };
  },
  mounted() {
    this.getsubjects();
  },
  methods: {
    async getsubjects() {
      //发送请求获取学生数据
      const data = await api.subjects.getsubjects({
        pageSize: this.pageSize, //每页显示条数
        currentPage: this.currentPage, //当前也
      });
      if (data.code) {
        // console.log(data.data);
        this.pages = data.data.pages;
        this.total = data.data.total;
        this.subjectsata = data.data.result;
      }
    },
    async deleteSubjects(_id) {
      const data = await api.subjects.deleteSubjects(_id);
      alert(data.message)
      console.log(data.message);
      if (data.code) {
        this.getsubjects()
      }
    },
  },
};
</script>

<style>
</style>